
var path = window.location.href;
var param = path.split("?")
var a=param[1].split("&")

var tit=a[2].split("=")
var title=tit[1].split(",")

var open=a[1].split("=")
var floor=open[1].split(",")

var image_url=decodeURIComponent(decodeURIComponent(decodeURIComponent(getQueryString("image_url"))))
var image_path=decodeURIComponent(decodeURIComponent(decodeURIComponent(getQueryString("image_path"))))
var r=null

$(function () {
    $("#title").val(decodeURI(title))
    $("#floor").val("F"+getQueryString("floor"))
    $("#url").val(image_url)
    $("#myImg").attr("src",image_path)
})
function changImg(e){
    var image = new Image();
    for (var i = 0; i < e.target.files.length; i++) {
        var file = e.target.files.item(i);
        if (!(/^image\/.*$/i.test(file.type))) {
            layer.msg('请上传图片!', {icon: 6, time: 2000});
            $("#file").val("")
            continue; //不是图片 就跳出这一次循环
        }
        //实例化FileReader API
        var freader = new FileReader();
        freader.readAsDataURL(file);
        freader.onload = function(e) {
            image.src =e.target.result ;
            image.onload = function() {
                if(file.size>5*1024*1024){
                    layer.msg('图片不得大于5M!', {icon: 6, time: 2000});
                    $("#file").val("")
                    return;
                }else{
                    if (this.width!=232&&this.height!=340){
                        layer.msg('场景图片大小限制为232*340!', {icon: 6, time: 2000});
                        r=1
                        $("#file").val("")
                        return;
                    } else {
                    $("#myImg").css({width:this.width+"px",height:this.height+"px",cursor:"pointer"});
                    $("#myImg").attr("src",e.target.result);
                    }
                }

            };
        }
    }
}
$("#form-member").validate({
    rules: {

    },
    //提交表单数据
    submitHandler:function(form){
        var formData = new FormData();
        formData.append("resource_id",getQueryString("resource_id"));
        // formData.append("category_id",getQueryString("category_id"));
        formData.append("image_url",$("#url").val());

        formData.append("started_at",'1000-01-01 00:00:00');
        formData.append("end_in",'1000-01-01 00:00:00');
        if (r==null){
            formData.append("file",$("#file")[0].files[0]);
        }
        var quzhi=JSON.parse(web.readCookie("loginData"))
        formData.append("last_modified_name",quzhi.user.username);
        formData.append("last_modified_by",quzhi.user.user_ID);
        console.log($("#file")[0].files[0])
        $.ajax({
            //192.168.0.107:7040
            url: root.sroreinter.save_resource_conf,
            cache: false,  //禁用缓存
            type: "POST",
            // 告诉jQuery不要去处理发送的数据
            processData : false,
            // 告诉jQuery不要去设置Content-Type请求头
            contentType : false,
            data: formData,
            success: function (data) {
                console.log(data)
                if (data.errorCode=="92"){
                    layer.msg('您添加的开始时间小于已存在数据的结束时间!', {icon: 6, time: 3000});
                }
                if(data.errorCode=="0") {
                    layer.msg('操作成功!', {icon: 6, time: 1000});
                    parent.isEdit = true;
                    parent.queryDataFn();
                    setTimeout( function () {
                        cancelLayerNoRefreshFn();
                    },700);
                }
            }
        });
    }
})
function removeIframe(){
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}
$('#pic').click(function (event) {
    event.preventDefault()
    $('#file').click()
})